From 6fe5203c0adcf6d40f0a550d540d8796539b1450 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Jard=C3=B3n?= Date: Sat, 5 Jun 2010 02:17:48 +0200 Subject: [PATCH] GtkFontSelection: move public members to private structure --- gtk/gtkfontsel.c | 347 ++++++++++++++++++++++++++--------------------- gtk/gtkfontsel.h | 21 +-- 2 files changed, 200 insertions(+), 168 deletions(-) diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c index 113d5a7a3f..9f9bed436a 100644 --- a/gtk/gtkfontsel.c +++ b/gtk/gtkfontsel.c @@ -61,6 +61,24 @@ #include "gtkprivate.h" #include "gtkbuildable.h" +struct _GtkFontSelectionPriv +{ + GtkWidget *font_entry; /* Used _get_family_entry() for consistency, -mr */ + GtkWidget *font_style_entry; /* Used _get_face_entry() for consistency, -mr */ + + GtkWidget *size_entry; + GtkWidget *preview_entry; + + GtkWidget *family_list; + GtkWidget *face_list; + GtkWidget *size_list; + + PangoFontFamily *family; /* Current family */ + PangoFontFace *face; /* Current face */ + + gint size; +}; + struct _GtkFontSelectionDialogPriv { @@ -191,7 +209,8 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - + + gobject_class->finalize = gtk_font_selection_finalize; gobject_class->set_property = gtk_font_selection_set_property; gobject_class->get_property = gtk_font_selection_get_property; @@ -212,7 +231,8 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass) P_("The text to display in order to demonstrate the selected font"), _(PREVIEW_TEXT), GTK_PARAM_READWRITE)); - gobject_class->finalize = gtk_font_selection_finalize; + + g_type_class_add_private (klass, sizeof (GtkFontSelectionPriv)); } static void @@ -288,6 +308,7 @@ list_row_activated (GtkWidget *widget) static void gtk_font_selection_init (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv; GtkWidget *scrolled_win; GtkWidget *text_box; GtkWidget *table, *label; @@ -298,10 +319,15 @@ gtk_font_selection_init (GtkFontSelection *fontsel) GList *focus_chain = NULL; AtkObject *atk_obj; + fontsel->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontsel, + GTK_TYPE_FONT_SELECTION, + GtkFontSelectionPriv); + priv = fontsel->priv; + gtk_widget_push_composite_child (); gtk_box_set_spacing (GTK_BOX (fontsel), 12); - fontsel->size = 12 * PANGO_SCALE; + priv->size = 12 * PANGO_SCALE; /* Create the table of font, style & size. */ table = gtk_table_new (3, 3, FALSE); @@ -311,30 +337,30 @@ gtk_font_selection_init (GtkFontSelection *fontsel) gtk_box_pack_start (GTK_BOX (fontsel), table, TRUE, TRUE, 0); #ifdef INCLUDE_FONT_ENTRIES - fontsel->font_entry = gtk_entry_new (); - gtk_editable_set_editable (GTK_EDITABLE (fontsel->font_entry), FALSE); - gtk_widget_set_size_request (fontsel->font_entry, 20, -1); - gtk_widget_show (fontsel->font_entry); - gtk_table_attach (GTK_TABLE (table), fontsel->font_entry, 0, 1, 1, 2, + priv->font_entry = gtk_entry_new (); + gtk_editable_set_editable (GTK_EDITABLE (priv->font_entry), FALSE); + gtk_widget_set_size_request (priv->font_entry, 20, -1); + gtk_widget_show (priv->font_entry); + gtk_table_attach (GTK_TABLE (table), priv->font_entry, 0, 1, 1, 2, GTK_FILL, 0, 0, 0); - fontsel->font_style_entry = gtk_entry_new (); - gtk_editable_set_editable (GTK_EDITABLE (fontsel->font_style_entry), FALSE); - gtk_widget_set_size_request (fontsel->font_style_entry, 20, -1); - gtk_widget_show (fontsel->font_style_entry); - gtk_table_attach (GTK_TABLE (table), fontsel->font_style_entry, 1, 2, 1, 2, + priv->font_style_entry = gtk_entry_new (); + gtk_editable_set_editable (GTK_EDITABLE (priv->font_style_entry), FALSE); + gtk_widget_set_size_request (priv->font_style_entry, 20, -1); + gtk_widget_show (priv->font_style_entry); + gtk_table_attach (GTK_TABLE (table), priv->font_style_entry, 1, 2, 1, 2, GTK_FILL, 0, 0, 0); #endif /* INCLUDE_FONT_ENTRIES */ - fontsel->size_entry = gtk_entry_new (); - gtk_widget_set_size_request (fontsel->size_entry, 20, -1); - gtk_widget_show (fontsel->size_entry); - gtk_table_attach (GTK_TABLE (table), fontsel->size_entry, 2, 3, 1, 2, + priv->size_entry = gtk_entry_new (); + gtk_widget_set_size_request (priv->size_entry, 20, -1); + gtk_widget_show (priv->size_entry); + gtk_table_attach (GTK_TABLE (table), priv->size_entry, 2, 3, 1, 2, GTK_FILL, 0, 0, 0); - g_signal_connect (fontsel->size_entry, "activate", + g_signal_connect (priv->size_entry, "activate", G_CALLBACK (gtk_font_selection_size_activate), fontsel); - g_signal_connect_after (fontsel->size_entry, "focus-out-event", + g_signal_connect_after (priv->size_entry, "focus-out-event", G_CALLBACK (gtk_font_selection_size_focus_out), fontsel); @@ -352,7 +378,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel) label = gtk_label_new_with_mnemonic (_("Si_ze:")); gtk_label_set_mnemonic_widget (GTK_LABEL (label), - fontsel->size_entry); + priv->size_entry); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 2, 3, 0, 1, @@ -364,10 +390,10 @@ gtk_font_selection_init (GtkFontSelection *fontsel) model = gtk_list_store_new (2, G_TYPE_OBJECT, /* FAMILY_COLUMN */ G_TYPE_STRING); /* FAMILY_NAME_COLUMN */ - fontsel->family_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); + priv->family_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); - g_signal_connect (fontsel->family_list, "row-activated", + g_signal_connect (priv->family_list, "row-activated", G_CALLBACK (list_row_activated), fontsel); column = gtk_tree_view_column_new_with_attributes ("Family", @@ -375,22 +401,22 @@ gtk_font_selection_init (GtkFontSelection *fontsel) "text", FAMILY_NAME_COLUMN, NULL); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_append_column (GTK_TREE_VIEW (fontsel->family_list), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (priv->family_list), column); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (fontsel->family_list), FALSE); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->family_list)), + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->family_list), FALSE); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_list)), GTK_SELECTION_BROWSE); - gtk_label_set_mnemonic_widget (GTK_LABEL (font_label), fontsel->family_list); + gtk_label_set_mnemonic_widget (GTK_LABEL (font_label), priv->family_list); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_set_size_request (scrolled_win, FONT_LIST_WIDTH, FONT_LIST_HEIGHT); - gtk_container_add (GTK_CONTAINER (scrolled_win), fontsel->family_list); + gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_list); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_widget_show (fontsel->family_list); + gtk_widget_show (priv->family_list); gtk_widget_show (scrolled_win); gtk_table_attach (GTK_TABLE (table), scrolled_win, 0, 1, 1, 3, @@ -401,44 +427,44 @@ gtk_font_selection_init (GtkFontSelection *fontsel) model = gtk_list_store_new (2, G_TYPE_OBJECT, /* FACE_COLUMN */ G_TYPE_STRING); /* FACE_NAME_COLUMN */ - fontsel->face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); + priv->face_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); - g_signal_connect (fontsel->face_list, "row-activated", + g_signal_connect (priv->face_list, "row-activated", G_CALLBACK (list_row_activated), fontsel); - gtk_label_set_mnemonic_widget (GTK_LABEL (style_label), fontsel->face_list); + gtk_label_set_mnemonic_widget (GTK_LABEL (style_label), priv->face_list); column = gtk_tree_view_column_new_with_attributes ("Face", gtk_cell_renderer_text_new (), "text", FACE_NAME_COLUMN, NULL); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_append_column (GTK_TREE_VIEW (fontsel->face_list), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (priv->face_list), column); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (fontsel->face_list), FALSE); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->face_list)), + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->face_list), FALSE); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->face_list)), GTK_SELECTION_BROWSE); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_set_size_request (scrolled_win, FONT_STYLE_LIST_WIDTH, FONT_LIST_HEIGHT); - gtk_container_add (GTK_CONTAINER (scrolled_win), fontsel->face_list); + gtk_container_add (GTK_CONTAINER (scrolled_win), priv->face_list); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_widget_show (fontsel->face_list); + gtk_widget_show (priv->face_list); gtk_widget_show (scrolled_win); gtk_table_attach (GTK_TABLE (table), scrolled_win, 1, 2, 1, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); focus_chain = g_list_append (focus_chain, scrolled_win); - focus_chain = g_list_append (focus_chain, fontsel->size_entry); + focus_chain = g_list_append (focus_chain, priv->size_entry); model = gtk_list_store_new (1, G_TYPE_INT); - fontsel->size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); + priv->size_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_unref (model); - g_signal_connect (fontsel->size_list, "row-activated", + g_signal_connect (priv->size_list, "row-activated", G_CALLBACK (list_row_activated), fontsel); column = gtk_tree_view_column_new_with_attributes ("Size", @@ -446,19 +472,19 @@ gtk_font_selection_init (GtkFontSelection *fontsel) "text", SIZE_COLUMN, NULL); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_append_column (GTK_TREE_VIEW (fontsel->size_list), column); + gtk_tree_view_append_column (GTK_TREE_VIEW (priv->size_list), column); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (fontsel->size_list), FALSE); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)), + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->size_list), FALSE); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list)), GTK_SELECTION_BROWSE); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (scrolled_win), fontsel->size_list); + gtk_container_add (GTK_CONTAINER (scrolled_win), priv->size_list); gtk_widget_set_size_request (scrolled_win, -1, FONT_LIST_HEIGHT); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); - gtk_widget_show (fontsel->size_list); + gtk_widget_show (priv->size_list); gtk_widget_show (scrolled_win); gtk_table_attach (GTK_TABLE (table), scrolled_win, 2, 3, 2, 3, GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -468,19 +494,19 @@ gtk_font_selection_init (GtkFontSelection *fontsel) g_list_free (focus_chain); /* Insert the fonts. */ - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->family_list)), "changed", + g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_list)), "changed", G_CALLBACK (gtk_font_selection_select_font), fontsel); - g_signal_connect_after (fontsel->family_list, "map", + g_signal_connect_after (priv->family_list, "map", G_CALLBACK (gtk_font_selection_scroll_on_map), fontsel); - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->face_list)), "changed", + g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->face_list)), "changed", G_CALLBACK (gtk_font_selection_select_style), fontsel); - g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)), "changed", + g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list)), "changed", G_CALLBACK (gtk_font_selection_select_size), fontsel); - atk_obj = gtk_widget_get_accessible (fontsel->size_list); + atk_obj = gtk_widget_get_accessible (priv->size_list); if (GTK_IS_ACCESSIBLE (atk_obj)) { /* Accessibility support is enabled. @@ -536,16 +562,16 @@ gtk_font_selection_init (GtkFontSelection *fontsel) gtk_widget_show (text_box); gtk_box_pack_start (GTK_BOX (vbox), text_box, FALSE, TRUE, 0); - fontsel->preview_entry = gtk_entry_new (); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), fontsel->preview_entry); - gtk_entry_set_text (GTK_ENTRY (fontsel->preview_entry), _(PREVIEW_TEXT)); + priv->preview_entry = gtk_entry_new (); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->preview_entry); + gtk_entry_set_text (GTK_ENTRY (priv->preview_entry), _(PREVIEW_TEXT)); - gtk_widget_show (fontsel->preview_entry); - g_signal_connect (fontsel->preview_entry, "changed", + gtk_widget_show (priv->preview_entry); + g_signal_connect (priv->preview_entry, "changed", G_CALLBACK (gtk_font_selection_preview_changed), fontsel); - gtk_widget_set_size_request (fontsel->preview_entry, + gtk_widget_set_size_request (priv->preview_entry, -1, INITIAL_PREVIEW_HEIGHT); - gtk_box_pack_start (GTK_BOX (text_box), fontsel->preview_entry, + gtk_box_pack_start (GTK_BOX (text_box), priv->preview_entry, TRUE, TRUE, 0); gtk_widget_pop_composite_child(); } @@ -570,11 +596,7 @@ gtk_font_selection_new (void) static void gtk_font_selection_finalize (GObject *object) { - GtkFontSelection *fontsel; - - g_return_if_fail (GTK_IS_FONT_SELECTION (object)); - - fontsel = GTK_FONT_SELECTION (object); + GtkFontSelection *fontsel = GTK_FONT_SELECTION (object); gtk_font_selection_ref_family (fontsel, NULL); gtk_font_selection_ref_face (fontsel, NULL); @@ -586,21 +608,25 @@ static void gtk_font_selection_ref_family (GtkFontSelection *fontsel, PangoFontFamily *family) { + GtkFontSelectionPriv *priv = fontsel->priv; + if (family) family = g_object_ref (family); - if (fontsel->family) - g_object_unref (fontsel->family); - fontsel->family = family; + if (priv->family) + g_object_unref (priv->family); + priv->family = family; } static void gtk_font_selection_ref_face (GtkFontSelection *fontsel, PangoFontFace *face) { + GtkFontSelectionPriv *priv = fontsel->priv; + if (face) face = g_object_ref (face); - if (fontsel->face) - g_object_unref (fontsel->face); - fontsel->face = face; + if (priv->face) + g_object_unref (priv->face); + priv->face = face; } static void @@ -674,14 +700,16 @@ set_cursor_to_iter (GtkTreeView *view, static void gtk_font_selection_scroll_to_selection (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv = fontsel->priv; + /* Try to scroll the font family list to the selected item */ - scroll_to_selection (GTK_TREE_VIEW (fontsel->family_list)); - + scroll_to_selection (GTK_TREE_VIEW (priv->family_list)); + /* Try to scroll the font family list to the selected item */ - scroll_to_selection (GTK_TREE_VIEW (fontsel->face_list)); - + scroll_to_selection (GTK_TREE_VIEW (priv->face_list)); + /* Try to scroll the font family list to the selected item */ - scroll_to_selection (GTK_TREE_VIEW (fontsel->size_list)); + scroll_to_selection (GTK_TREE_VIEW (priv->size_list)); /* This is called when the list is mapped. Here we scroll to the current font if necessary. */ } @@ -699,6 +727,7 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, gpointer data) { GtkFontSelection *fontsel; + GtkFontSelectionPriv *priv; GtkTreeModel *model; GtkTreeIter iter; #ifdef INCLUDE_FONT_ENTRIES @@ -706,21 +735,22 @@ gtk_font_selection_select_font (GtkTreeSelection *selection, #endif fontsel = GTK_FONT_SELECTION (data); + priv = fontsel->priv; if (gtk_tree_selection_get_selected (selection, &model, &iter)) { PangoFontFamily *family; - + gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1); - if (fontsel->family != family) + if (priv->family != family) { gtk_font_selection_ref_family (fontsel, family); - + #ifdef INCLUDE_FONT_ENTRIES - family_name = pango_font_family_get_name (fontsel->family); - gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name); + family_name = pango_font_family_get_name (priv->family); + gtk_entry_set_text (GTK_ENTRY (priv->font_entry), family_name); #endif - + gtk_font_selection_show_available_styles (fontsel); gtk_font_selection_select_best_style (fontsel, TRUE); } @@ -741,14 +771,15 @@ cmp_families (const void *a, const void *b) static void gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv = fontsel->priv; GtkListStore *model; PangoFontFamily **families; PangoFontFamily *match_family = NULL; gint n_families, i; GtkTreeIter match_row; - - model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->family_list))); - + + model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->family_list))); + pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)), &families, &n_families); qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families); @@ -776,9 +807,9 @@ gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel) gtk_font_selection_ref_family (fontsel, match_family); if (match_family) { - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &match_row); + set_cursor_to_iter (GTK_TREE_VIEW (priv->family_list), &match_row); #ifdef INCLUDE_FONT_ENTRIES - gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), + gtk_entry_set_text (GTK_ENTRY (priv->font_entry), pango_font_family_get_name (match_family)); #endif /* INCLUDE_FONT_ENTRIES */ } @@ -837,21 +868,22 @@ font_description_style_equal (const PangoFontDescription *a, static void gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv = fontsel->priv; gint n_faces, i; PangoFontFace **faces; PangoFontDescription *old_desc; GtkListStore *model; GtkTreeIter match_row; PangoFontFace *match_face = NULL; - - model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list))); - - if (fontsel->face) - old_desc = pango_font_face_describe (fontsel->face); + + model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list))); + + if (priv->face) + old_desc = pango_font_face_describe (priv->face); else old_desc= NULL; - pango_font_family_list_faces (fontsel->family, &faces, &n_faces); + pango_font_family_list_faces (priv->family, &faces, &n_faces); qsort (faces, n_faces, sizeof (PangoFontFace *), faces_sort_func); gtk_list_store_clear (model); @@ -893,11 +925,11 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel) if (match_face) { #ifdef INCLUDE_FONT_ENTRIES - const gchar *str = pango_font_face_get_face_name (fontsel->face); + const gchar *str = pango_font_face_get_face_name (priv->face); - gtk_entry_set_text (GTK_ENTRY (fontsel->font_style_entry), str); -#endif - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &match_row); + gtk_entry_set_text (GTK_ENTRY (priv->font_style_entry), str); +#endif + set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &match_row); } g_free (faces); @@ -912,15 +944,16 @@ static void gtk_font_selection_select_best_style (GtkFontSelection *fontsel, gboolean use_first) { + GtkFontSelectionPriv *priv = fontsel->priv; GtkTreeIter iter; GtkTreeModel *model; - model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list)); if (gtk_tree_model_get_iter_first (model, &iter)) { - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &iter); - scroll_to_selection (GTK_TREE_VIEW (fontsel->face_list)); + set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &iter); + scroll_to_selection (GTK_TREE_VIEW (priv->face_list)); } gtk_font_selection_show_available_sizes (fontsel, FALSE); @@ -936,7 +969,7 @@ gtk_font_selection_select_style (GtkTreeSelection *selection, GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); GtkTreeModel *model; GtkTreeIter iter; - + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { PangoFontFace *face; @@ -954,12 +987,13 @@ static void gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, gboolean first_time) { + GtkFontSelectionPriv *priv = fontsel->priv; gint i; GtkListStore *model; gchar buffer[128]; gchar *p; - - model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->size_list))); + + model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->size_list))); /* Insert the standard font sizes */ if (first_time) @@ -969,25 +1003,25 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, for (i = 0; i < G_N_ELEMENTS (font_sizes); i++) { GtkTreeIter iter; - + gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, SIZE_COLUMN, font_sizes[i], -1); - - if (font_sizes[i] * PANGO_SCALE == fontsel->size) - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->size_list), &iter); + + if (font_sizes[i] * PANGO_SCALE == priv->size) + set_cursor_to_iter (GTK_TREE_VIEW (priv->size_list), &iter); } } else { GtkTreeIter iter; gboolean found = FALSE; - + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter); for (i = 0; i < G_N_ELEMENTS (font_sizes) && !found; i++) { - if (font_sizes[i] * PANGO_SCALE == fontsel->size) + if (font_sizes[i] * PANGO_SCALE == priv->size) { - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->size_list), &iter); + set_cursor_to_iter (GTK_TREE_VIEW (priv->size_list), &iter); found = TRUE; } @@ -996,7 +1030,7 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, if (!found) { - GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list)); + GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->size_list)); gtk_tree_selection_unselect_all (selection); } } @@ -1004,7 +1038,7 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, /* Set the entry to the new size, rounding to 1 digit, * trimming of trailing 0's and a trailing period */ - g_snprintf (buffer, sizeof (buffer), "%.1f", fontsel->size / (1.0 * PANGO_SCALE)); + g_snprintf (buffer, sizeof (buffer), "%.1f", priv->size / (1.0 * PANGO_SCALE)); if (strchr (buffer, '.')) { p = buffer + strlen (buffer) - 1; @@ -1016,8 +1050,8 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel, } /* Compare, to avoid moving the cursor unecessarily */ - if (strcmp (gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)), buffer) != 0) - gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer); + if (strcmp (gtk_entry_get_text (GTK_ENTRY (priv->size_entry)), buffer) != 0) + gtk_entry_set_text (GTK_ENTRY (priv->size_entry), buffer); } static void @@ -1030,9 +1064,11 @@ static void gtk_font_selection_set_size (GtkFontSelection *fontsel, gint new_size) { - if (fontsel->size != new_size) + GtkFontSelectionPriv *priv = fontsel->priv; + + if (priv->size != new_size) { - fontsel->size = new_size; + priv->size = new_size; gtk_font_selection_show_available_sizes (fontsel, FALSE); gtk_font_selection_load_font (fontsel); @@ -1045,16 +1081,15 @@ static void gtk_font_selection_size_activate (GtkWidget *w, gpointer data) { - GtkFontSelection *fontsel; + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + GtkFontSelectionPriv *priv = fontsel->priv; gint new_size; const gchar *text; - - fontsel = GTK_FONT_SELECTION (data); - text = gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)); + text = gtk_entry_get_text (GTK_ENTRY (priv->size_entry)); new_size = MAX (0.1, atof (text) * PANGO_SCALE + 0.5); - if (fontsel->size != new_size) + if (priv->size != new_size) gtk_font_selection_set_size (fontsel, new_size); else list_row_activated (w); @@ -1065,17 +1100,16 @@ gtk_font_selection_size_focus_out (GtkWidget *w, GdkEventFocus *event, gpointer data) { - GtkFontSelection *fontsel; + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); + GtkFontSelectionPriv *priv = fontsel->priv; gint new_size; const gchar *text; - - fontsel = GTK_FONT_SELECTION (data); - text = gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry)); + text = gtk_entry_get_text (GTK_ENTRY (priv->size_entry)); new_size = MAX (0.1, atof (text) * PANGO_SCALE + 0.5); gtk_font_selection_set_size (fontsel, new_size); - + return TRUE; } @@ -1084,13 +1118,11 @@ static void gtk_font_selection_select_size (GtkTreeSelection *selection, gpointer data) { - GtkFontSelection *fontsel; + GtkFontSelection *fontsel = GTK_FONT_SELECTION (data); GtkTreeModel *model; GtkTreeIter iter; gint new_size; - - fontsel = GTK_FONT_SELECTION (data); - + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, SIZE_COLUMN, &new_size, -1); @@ -1107,12 +1139,13 @@ gtk_font_selection_load_font (GtkFontSelection *fontsel) static PangoFontDescription * gtk_font_selection_get_font_description (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv = fontsel->priv; PangoFontDescription *font_desc; - if (fontsel->face) + if (priv->face) { - font_desc = pango_font_face_describe (fontsel->face); - pango_font_description_set_size (font_desc, fontsel->size); + font_desc = pango_font_face_describe (priv->face); + pango_font_description_set_size (font_desc, priv->size); } else font_desc = pango_font_description_from_string (DEFAULT_FONT_NAME); @@ -1129,10 +1162,11 @@ gtk_font_selection_get_font_description (GtkFontSelection *fontsel) static void gtk_font_selection_update_preview (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv = fontsel->priv; GtkRcStyle *rc_style; gint new_height; GtkRequisition old_requisition; - GtkWidget *preview_entry = fontsel->preview_entry; + GtkWidget *preview_entry = priv->preview_entry; const gchar *text; gtk_widget_get_child_requisition (preview_entry, &old_requisition); @@ -1178,8 +1212,8 @@ GtkWidget * gtk_font_selection_get_family_list (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->family_list; + + return fontsel->priv->family_list; } /** @@ -1197,8 +1231,8 @@ GtkWidget * gtk_font_selection_get_face_list (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->face_list; + + return fontsel->priv->face_list; } /** @@ -1216,8 +1250,8 @@ GtkWidget * gtk_font_selection_get_size_entry (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->size_entry; + + return fontsel->priv->size_entry; } /** @@ -1234,8 +1268,8 @@ GtkWidget * gtk_font_selection_get_size_list (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->size_list; + + return fontsel->priv->size_list; } /** @@ -1252,8 +1286,8 @@ GtkWidget * gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->preview_entry; + + return fontsel->priv->preview_entry; } /** @@ -1273,8 +1307,8 @@ PangoFontFamily * gtk_font_selection_get_family (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->family; + + return fontsel->priv->family; } /** @@ -1294,8 +1328,8 @@ PangoFontFace * gtk_font_selection_get_face (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - - return fontsel->face; + + return fontsel->priv->face; } /** @@ -1313,8 +1347,8 @@ gint gtk_font_selection_get_size (GtkFontSelection *fontsel) { g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1); - - return fontsel->size; + + return fontsel->priv->size; } /** @@ -1356,6 +1390,7 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, PangoFontFamily **pfamily, PangoFontFace **pface) { + GtkFontSelectionPriv *priv = fontsel->priv; PangoFontFamily *new_family = NULL; PangoFontFace *new_face = NULL; PangoFontFace *fallback_face = NULL; @@ -1372,7 +1407,7 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, /* Check to make sure that this is in the list of allowed fonts */ - model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->family_list)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->family_list)); for (valid = gtk_tree_model_get_iter_first (model, &iter); valid; valid = gtk_tree_model_iter_next (model, &iter)) @@ -1398,10 +1433,10 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, *pfamily = new_family; else g_object_unref (new_family); - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &iter); + set_cursor_to_iter (GTK_TREE_VIEW (priv->family_list), &iter); gtk_font_selection_show_available_styles (fontsel); - model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->face_list)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->face_list)); for (valid = gtk_tree_model_get_iter_first (model, &iter); valid; valid = gtk_tree_model_iter_next (model, &iter)) @@ -1440,7 +1475,7 @@ gtk_font_selection_select_font_desc (GtkFontSelection *fontsel, *pface = new_face; else if (new_face) g_object_unref (new_face); - set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &match_iter); + set_cursor_to_iter (GTK_TREE_VIEW (priv->face_list), &match_iter); gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc)); @@ -1514,9 +1549,13 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel, G_CONST_RETURN gchar* gtk_font_selection_get_preview_text (GtkFontSelection *fontsel) { + GtkFontSelectionPriv *priv; + g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL); - return gtk_entry_get_text (GTK_ENTRY (fontsel->preview_entry)); + priv = fontsel->priv; + + return gtk_entry_get_text (GTK_ENTRY (priv->preview_entry)); } @@ -1532,10 +1571,14 @@ void gtk_font_selection_set_preview_text (GtkFontSelection *fontsel, const gchar *text) { + GtkFontSelectionPriv *priv; + g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel)); g_return_if_fail (text != NULL); - gtk_entry_set_text (GTK_ENTRY (fontsel->preview_entry), text); + priv = fontsel->priv; + + gtk_entry_set_text (GTK_ENTRY (priv->preview_entry), text); } /***************************************************************************** diff --git a/gtk/gtkfontsel.h b/gtk/gtkfontsel.h index 912d38111a..b829464ea5 100644 --- a/gtk/gtkfontsel.h +++ b/gtk/gtkfontsel.h @@ -59,6 +59,7 @@ G_BEGIN_DECLS typedef struct _GtkFontSelection GtkFontSelection; +typedef struct _GtkFontSelectionPriv GtkFontSelectionPriv; typedef struct _GtkFontSelectionClass GtkFontSelectionClass; typedef struct _GtkFontSelectionDialog GtkFontSelectionDialog; @@ -68,22 +69,9 @@ typedef struct _GtkFontSelectionDialogClass GtkFontSelectionDialogClass; struct _GtkFontSelection { GtkVBox parent_instance; - - GtkWidget *GSEAL (font_entry); /* Used _get_family_entry() for consistency, -mr */ - GtkWidget *GSEAL (family_list); - GtkWidget *GSEAL (font_style_entry); /* Used _get_face_entry() for consistency, -mr */ - GtkWidget *GSEAL (face_list); - GtkWidget *GSEAL (size_entry); - GtkWidget *GSEAL (size_list); - GtkWidget *GSEAL (pixels_button); /* Unused, -mr */ - GtkWidget *GSEAL (points_button); /* Unused, -mr */ - GtkWidget *GSEAL (filter_button); /* Unused, -mr */ - GtkWidget *GSEAL (preview_entry); - - PangoFontFamily *GSEAL (family); /* Current family */ - PangoFontFace *GSEAL (face); /* Current face */ - - gint GSEAL (size); + + /* */ + GtkFontSelectionPriv *priv; }; struct _GtkFontSelectionClass @@ -97,6 +85,7 @@ struct _GtkFontSelectionClass void (*_gtk_reserved4) (void); }; + struct _GtkFontSelectionDialog { GtkDialog parent_instance; -- 2.30.2